package com.ln.zxdk.core.controller;


import com.ln.common.core.config.result.R;
import com.ln.zxdk.core.pojo.IntegralGrade;
import com.ln.zxdk.core.service.IntegralGradeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 积分等级表 前端控制器
 * </p>
 *
 * @author 赵明硕
 * @since 2022-09-30
 */
@RestController
@RequestMapping("/admin/core/integralGrade")
@Api(tags = "积分等级管理")
@Log4j2
public class IntegralGradeController {
    @Resource
    private IntegralGradeService integralGradeService;

    @GetMapping("/list")
    @ApiOperation("积分等级列表")
    public R listAll(){
        List<IntegralGrade> list = integralGradeService.list();
        return R.ok().data("list",list);
    }

    @DeleteMapping("/remove/{id}")
    @ApiOperation(value = "根据id删除积分等级", notes = "逻辑删除")
    public R removeById(@PathVariable Long id){
        boolean remove = integralGradeService.removeById(id);
        if (remove){
           return R.ok().message("删除成功");
       }else {
           return R.error().message("删除失败");
       }
    }

    @PostMapping("/save")
    @ApiOperation("新增积分等级")
    public R save(@ApiParam(value = "积分等级对象", required = true) @RequestBody IntegralGrade integralGrade){
        boolean save = integralGradeService.save(integralGrade);
        if (save){
            return R.ok().message("新增成功");
        }else {
            return R.error().message("新增失败");
        }
    }

    @GetMapping("/getById/{id}")
    @ApiOperation("根据id获取积分等级")
    public R getById(@ApiParam(value = "数据id", required = true, example = "1") @PathVariable Long id){
        IntegralGrade integralGrade = integralGradeService.getById(id);
        if (integralGrade!=null){
            return R.ok().data("data",integralGrade);
        }else {
            return R.error().message("数据不存在");
        }
    }

    @PutMapping("/update")
    @ApiOperation("修改积分等级")
    public R update(@ApiParam(value = "积分等级对象", required = true) @RequestBody IntegralGrade integralGrade){
        boolean b = integralGradeService.updateById(integralGrade);
        if (b){
            return R.ok().message("修改成功");
        }else {
            return R.error().message("修改失败");
        }
    }
}

